home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lanutsrc.zip / HARDWARE.C < prev    next >
Text File  |  1991-03-13  |  6KB  |  195 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <malloc.h>
  5. #include <io.h>
  6. #include <dos.h>
  7.  
  8. #include "lantasti.h"
  9.  
  10. /*  ********************************************************************
  11. Reports the amount of EMS memory available in kilobytes.
  12. *****************************************************************************/
  13. int ems_avail() {
  14.   int handle;
  15.   union REGS regs;
  16.  
  17. /* see if an EMS driver has been loaded */  
  18.   handle = open("EMMXXXX0",O_RDONLY);
  19.   if (handle < 0) return(0);
  20.   close(handle);
  21.   
  22. /* find out how many pages are available */
  23.   regs.h.ah = 0x42;          /* get unallocated page count */
  24.   int86(0x67,®s,®s);      /* call the EMS handler */
  25.   
  26.   return(16 * regs.x.bx);       /* return the available memory */
  27. }
  28.  
  29. /*  ********************************************************************
  30. Report current DOS version
  31. *****************************************************************************/
  32. int get_dos_version() {
  33.   union REGS regs;
  34.   int result;
  35.   
  36.   regs.h.ah = 0x30;        /* get version # */
  37.   intdos(®s,®s);
  38.   
  39.   if (regs.h.al >= 2) result = (100 * regs.h.al) + regs.h.ah;
  40.   else result = 100;
  41.   
  42.   return(result);
  43. }
  44.  
  45. /*  ********************************************************************
  46. Report current LANOS version
  47. ************************************************************************/
  48. int get_lan_version() {
  49.   union REGS regs;
  50.   int result;
  51.   
  52.   regs.x.ax = 0xB809;
  53.   int86(0x2F,®s,®s);
  54.   
  55.   if (regs.h.ah >= 2) result = (100 * regs.h.ah) + regs.h.al;
  56.   else result = 0;
  57.   
  58.   return(result);
  59. }
  60.  
  61. /* disk_space ****************************************************************
  62.  Return free disk space (in K) on current drive.
  63.  12/13/88 JEM
  64. ******************************************************************************/
  65. int disk_space() {
  66.   unsigned long result;
  67.   union REGS regs;
  68.   
  69.   regs.h.ah = 0x36;                 /* get free space interrupt */
  70.   regs.h.dl = 0;                    /* select default drive */
  71.   int86(0x21,®s,®s);
  72.  
  73.   result =  (unsigned long) regs.x.ax;    /* sectors per cluster */
  74.   result *= (unsigned long) regs.x.bx;    /* number of free clusters */
  75.   result *= (unsigned long) regs.x.cx;    /* bytes per sector */
  76.   return((int) (result / 1024));
  77. }
  78. /*  ************************************************************************
  79. Determine the largest contiguous free RAM area
  80. *****************************************************************************/
  81. #define KBYTE 1024
  82. int ram_free() {
  83.   char huge *memory;
  84.   long count,left,right;
  85.   
  86.   left = 1 ; right = 600;
  87.   
  88.   do {
  89.     count = (left + right) / 2;
  90.     memory = halloc(count,KBYTE);
  91.     if (memory == NULL) right = count - 1;
  92.     else {
  93.       hfree(memory);
  94.       left = count + 1;
  95.     }
  96.   } while (left < right);
  97.  
  98.   count += 0;  /* add this program's space back in */
  99.   
  100.   return((int) count);
  101. }   
  102.  
  103. /*  ********************************************************************
  104. Returns TRUE if an MS Compatible mouse driver is running
  105. *****************************************************************************/
  106. mouse_present() {
  107.   union REGS regs;
  108.   
  109.   regs.x.ax = 0;        /* attempt to initialize mouse */
  110.   int86(0x33,®s,®s);
  111.   if (regs.x.ax) return(TRUE);
  112.   else return(FALSE);
  113. }
  114.  
  115. /* find_6845 ********************************************************************
  116. Returns TRUE if a CRT controller lives at the given address
  117. *****************************************************************************/
  118. int find_6845(addr)
  119.   int addr;
  120. {
  121.   unsigned char oldval;
  122.   int result,i;
  123.  
  124.   outp(addr,0xF);        /* select cursor low scan line register */
  125.   
  126.   addr += 1;
  127.   oldval = inp(addr);        /* save current value */
  128.   outp(addr,0x66);        /* try to write trash */
  129.   for (i = 0;i < 100; i++) ;    /* wait for chip to respond */
  130.   
  131.   result = (0x66 == inp(addr)); /* see if we wrote the value correctly */
  132.   outp(addr,oldval);        /* restore original value */
  133.   return(result);
  134. }
  135.  
  136. /* video_type ********************************************************************
  137. Returns video type - 0 = mono, 1 = herc, 2 = cga, 3 = ega, 4 = mcga/vga
  138. *****************************************************************************/
  139. int video_type() {
  140.   union REGS regs;
  141.   unsigned char oldval;
  142.   int i;
  143.  
  144. /* check for VGA card */
  145.   regs.x.ax = 0x1200;
  146.   regs.x.bx = 0x0036;
  147.   int86(0x10,®s,®s);
  148.   
  149.   if (regs.h.al == 0x12) return(4);
  150.  
  151. /* check for an EGA card */
  152.   regs.x.ax = 0x1200;               
  153.   regs.x.bx = 0x0010;
  154.   regs.x.cx = 0xF;
  155.   int86(0x10,®s,®s);
  156.   
  157.   if (regs.h.bl != 0x10) return(3);
  158.  
  159.  /* is it a CGA card? */
  160.   if(find_6845(0x3D4)) return(2); 
  161.  
  162. /* is it a monochrome or hercules card? */
  163.   if (!find_6845(0x3B4)) {
  164.     puts("Error: Unknown video system");
  165.     exit(-1);
  166.   }
  167.   
  168. /* see if it's a herc */
  169.   oldval = inp(0x3BA) & 0x80;   /* status port */
  170.   
  171. /* wait around to see if the status register changes */
  172.   for (i = 0;i < 5000; i++)    
  173. /* if it changes, it's a hercules card of some type */  
  174.     if (oldval != (inp(0x3BA) & 0x80)) return(1);
  175.     
  176. /* if it doesn't, we've got a plain old mono monitor */
  177.   return(0);    
  178. }
  179. /*  ********************************************************************
  180. Report the amount of extended memory available, in Kbytes
  181. *****************************************************************************/
  182. int ext_avail() {
  183.   union REGS regs;
  184.   
  185.   if (cpu_type() < 286) return(0);
  186.  
  187.   regs.x.ax = 0x8800;            /* get ext size fn */
  188.   int86(0x15,®s,®s);
  189.   
  190.   if (regs.x.ax == 0x8800) return(0);   /* function not supported */
  191.   
  192.   return(regs.x.ax);            /* return ext. memory size */
  193. }
  194. 
  195.